package tec;

public abstract class PassagerAbstrait implements Passager,Usager {

    private EtatPassager etat;
    private java.lang.String nom;
    private int destination;
    
    public Caractere caractere;
    public Placement placement;
    
    public PassagerAbstrait(java.lang.String nom, int destination)
    {
		etat = EtatPassager.DEHORS;
		this.nom = nom;
		this.destination = destination;
    }
	
    public final void accepterPlaceAssise() {
		etat = EtatPassager.ASSIS;
    }

    public final void accepterPlaceDebout() {
		etat = EtatPassager.DEBOUT;
    }

    public final void accepterSortie() {
		etat = EtatPassager.DEHORS;
    }

    public final boolean estAssis() {
		return (etat.estAssis());
    }

    public final boolean estDebout() {
		return (etat.estDebout());
    }

    public final boolean estDehors() {
		return (etat.estExterieur());
    }

    public java.lang.String nom() {
		return nom;
    }
    
    protected final int getDestination() {
		return destination;
	}

    public String toString() {
	java.lang.String position = new java.lang.String();
	if(estAssis())
	    position = new java.lang.String("assis");
	else if(estDebout())
	    position = new java.lang.String("debout");
	else if(estDehors())
	    position = new java.lang.String("dehors");
	
	return nom + " " + position  +", dest:"+getDestination(); 
    }
    
    public void monterDans(Transport t) throws TecInvalidException
    {
    	if(!(t instanceof Bus)){ 
    		throw new TecInvalidException("is not instance of BUS");
    	}
		Bus b = (Bus) t;
		choixPlaceMontee(b);
    }

    public void nouvelArret(Bus bus, int numeroArret) {
			if(numeroArret >= getDestination())
			{	
				bus.demanderSortie(this);
			}
			else
				choixChangerPlace(bus, numeroArret);
    }
    
	protected void choixPlaceMontee(Bus b)	 {
		 
		 placement.choixPlaceMontee(b, this);
	 }
	
	protected void choixChangerPlace(Bus b, int arret)
	 {
		 
		 caractere.choixChangerPlace(b, arret, this);
	 }
    
}
